package com.xu.controller;

import com.xu.mapper.JournalMapper;
import com.xu.pojo.Journal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class JournalController {

    @Autowired
    private JournalMapper journalMapper;

    @RequestMapping("/toJournal")
    public String toJournal(Model model)
    {
        List<Journal> journals = journalMapper.queryAllJournal();
        model.addAttribute("journals", journals);
        return "admin/journal/journal";
    }

    @ResponseBody
    @RequestMapping("/journalPage")
    public List<Journal> journalPage(@RequestParam(value = "start", required = false) Integer num,
                                     @RequestParam(value = "length", required = false) Integer page) {
        if (num == null) {
            num = 0;
        }
        if (page == null) {
            page = 10; // 默认每页显示 10 条记录
        }
        List<Journal> journals = journalMapper.journalPage(num, page);
        return journals;
    }
}
